using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class card_s : MonoBehaviour
{
    BoxCollider2D coll;
    bool isdrag = false;
    Vector2 things;
    Vector2 mouse;
    Vector2 der;

    Vector2 originalpos;

    void Start()
    {
        coll = GetComponent<BoxCollider2D>();
    }
    private void Awake()
    {
        originalpos = transform.position;
        Debug.Log("position starting");

    }
    private void Update()
    {
        if (!isdrag)
        {
            transform.position = Vector2.Lerp(transform.position, originalpos, 0.9f*Time.deltaTime);
        }
    }
    private void OnMouseDrag()
    {
        Vector2 current_M=Camera.main.ScreenToWorldPoint(Input.mousePosition);
        Move_thing(current_M);
    }
    private void OnMouseUp()
    {
        isdrag = false;
    }
    private void OnMouseDown()
    {
        isdrag = true;
        Start_mouse();
    }
    void Start_mouse()
    {
        
        things = transform.position;
        mouse = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        der = (Vector2)transform.position - mouse; 
    }

    void Move_thing(Vector2 current_M)
    {
        transform.position = Vector2.Lerp(transform.position, current_M + der, 0.2f);
    }
}